package com.marion.airec.service;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.airec.model.v20181012.PushDocumentRequest;
import com.aliyuncs.airec.model.v20181012.PushDocumentResponse;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.springframework.stereotype.Service;

/**
 * @author Marion
 * @date 2022/2/22 17:53
 */
@Service
public class AirecService {

    private static final String accessKeyId = "输入您的 access key";
    private static final String accessKeySecret = "输入您的 access key secret";

    // 推送数据：https://help.aliyun.com/document_detail/101482.html?spm=a2c4g.11186623.0.0.35c763e0DioSOa
    public void pushData() {
        //注意：下面的区域要和购买实例所在区域一致,如是北京区域,则填cn-beijing
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
        //注意：下面的区域要和购买实例所在区域一致,如是北京区域,则填("cn-beijing", "Airec", "airec.cn-beijing.aliyuncs.com")
        DefaultProfile.addEndpoint("cn-beijing", "Airec", "airec.cn-beijing.aliyuncs.com");

        DefaultAcsClient client = new DefaultAcsClient(profile);

        PushDocumentRequest request = new PushDocumentRequest();
        request.setAcceptFormat(FormatType.JSON);

        //填入实例id
        request.setInstanceId("airec-xxxx");
        //填入要上报的数据表名：user/item/behavior
        request.setTableName("item");

        String content = "要上报到智能推荐的json数据";
        request.setHttpContent(content.getBytes(), "UTF-8", FormatType.JSON);

        try {
            PushDocumentResponse response = client.getAcsResponse(request);
            System.out.println(response.getResult());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 获得推荐结果：https://help.aliyun.com/document_detail/101483.html?spm=a2c4g.11186623.0.0.35c763e0DioSOa
    public void getData() {
        //
    }

}
